#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
    // 打开文件
    FILE *fp = fopen("1_时间.txt", "w");
    // 文件写入
    while (1)
    {
        time_t T_1;
        T_1 = time(NULL);
        struct tm *l_time = localtime(&T_1);

        sleep(1);

        fseek(fp, 0, SEEK_SET);
        fwrite(l_time, sizeof(time_t), sizeof(T_1) / sizeof(time_t), fp);
        // 文件读取
        fseek(fp, 0, SEEK_SET);
        fread(l_time, sizeof(time_t), sizeof(T_1) / sizeof(time_t), fp);
        printf("%d年%d月%d日%d时%d分%d秒\n", l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday, l_time->tm_hour, l_time->tm_min, l_time->tm_sec);
    }
    // 文件关闭
    fclose(fp);
    return 0;
}
